import http from './http'

let ChannelCache = null

export const getChannel = async() =>{
    if(ChannelCache == null){
        ChannelCache = await http.fetchGet('/api/channel/all');
    }
    return ChannelCache.map(c=>{ return {...c} })
}

export const getChannelWithEnable = async() =>{
    if(ChannelCache == null){
        ChannelCache = await http.fetchGet('/api/channel/all');
    }
    return ChannelCache.filter(c=> !c.disable).map(c=>{ return {...c} })
}

export const save = async(item) =>{
    ChannelCache = null
    await http.fetchPost('/api/channel/save', item)
}
export const update = async(item) =>{
    ChannelCache = null
    await http.fetchPost('/api/channel/update', item)
}